package bb.lanxing.util.shape;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.view.View;
import bb.lanxing.util.DensityUtil;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

public class XzShape {
    public static final int OVAL = 1;
    public static final int RECTANGLE = 0;
    private static final String TAG = "XzShape";
    private int backgroundColor;
    Context context;
    private boolean isBackgroundColor;
    private boolean isLine;
    private boolean isRadius;
    private int lineColor;
    private int lineWidth;
    private float radius;
    private int shape;

    @Retention(RetentionPolicy.SOURCE)

    public @interface Shape {
    }

    public XzShape(Context context) {
        this.shape = 0;
        this.lineWidth = 1;
        this.radius = 0.0f;
        this.context = context;
    }

    public XzShape(Context context, int i) {
        this.lineWidth = 1;
        this.radius = 0.0f;
        this.context = context;
        this.shape = i;
    }

    public XzShape solid(int i) {
        this.isBackgroundColor = true;
        this.backgroundColor = this.context.getResources().getColor(i);
        return this;
    }

    public XzShape solidColor(int i) {
        this.isBackgroundColor = true;
        this.backgroundColor = i;
        return this;
    }

    public XzShape solid(String str) {
        this.isBackgroundColor = true;
        this.backgroundColor = Color.parseColor(str);
        return this;
    }

    public XzShape line(int i, int i2) {
        this.isLine = true;
        this.lineWidth = i;
        this.lineColor = this.context.getResources().getColor(i2);
        return this;
    }

    public XzShape lineColor(int i, int i2) {
        this.isLine = true;
        this.lineWidth = i;
        this.lineColor = i2;
        return this;
    }

    public XzShape line(int i, String str) {
        this.isLine = true;
        this.lineWidth = i;
        this.lineColor = Color.parseColor(str);
        return this;
    }

    public XzShape radius(float f) {
        this.isRadius = true;
        this.radius = f;
        return this;
    }

    public void into(View view) {
        view.setBackground(createShape());
    }

    public Drawable build() {
        return createShape();
    }

    private Drawable createShape() {
        GradientDrawable gradientDrawable = new GradientDrawable();
        if (this.shape == 1) {
            gradientDrawable.setShape(GradientDrawable.OVAL);
        } else {
            gradientDrawable.setShape(GradientDrawable.RECTANGLE);
        }
        if (this.isRadius) {
            gradientDrawable.setCornerRadius(this.radius);
        }
        if (this.isBackgroundColor) {
            gradientDrawable.setColor(this.backgroundColor);
        }
        if (this.isLine) {
            gradientDrawable.setStroke(DensityUtil.px2dp(this.lineWidth), this.lineColor);
        }
        return gradientDrawable;
    }
}
